package com.geekaca.service.impl;

import com.geekaca.dao.BookMapper;
import com.geekaca.domain.Book;
import com.geekaca.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.util.List;

@Component("bookService")
@Scope("singleton")
public class BookServiceImpl implements BookService {
    @Autowired
//    @Qualifier("bookMapper")
    private BookMapper bookDao;

    public void setBookDao(BookMapper bookDao) {
        this.bookDao = bookDao;
    }

//    @Autowired
//    private BookMapper2 bookMapper;
//
//    public void setBookMapper(BookMapper2 bookMapper) {
//        this.bookMapper = bookMapper;
//    }

//    @Autowired
//    private DataSource dataSource;
//
//    public void setDataSource(DataSource dataSource) {
//        this.dataSource = dataSource;
//    }

    @Override
    public void show() {

//        try(Connection connection = dataSource.getConnection();){
//            System.out.println(connection.getMetaData().getDatabaseProductName());
//        } catch (SQLException throwables) {
//            throwables.printStackTrace();
//        }

        System.out.println("bookservice show...");
//        String info = bookMapper.info;
//        System.out.println(info);
        Book book = new Book();
        book.setName("民时间故事");
        book.setDescription("大这故事");
        book.setType("文学");
        bookDao.save(book);
    }

    @Override
    public List<Book> getAll() {
        return bookDao.selectAll();
    }

    @PostConstruct
    public void doInit(){
        System.out.println("doInit");
    }

    @PreDestroy
    public void MyDestory(){
        System.out.println("MyDestory");
    }
}
